home *** CD-ROM | disk | FTP | other *** search
/ MACup: Giveaway 1996 / Image.iso / Shareware & Demos / Web-Publishing / SNAP PrimeBase / PrimeBase™ Server PPC / Setup / Scripts / backuphelp.dal < prev    next >
Encoding:
Text File  |  1996-07-13  |  10.7 KB  |  386 lines  |  [TEXT/ds30]

  1. /*
  2. execute file "BackupHelp";
  3.  
  4. SIMPLE SERVER MANAGEMENT MODEL
  5. ==============================
  6.  
  7. */
  8.  
  9. /* ******************************************************************************************** */
  10. /*                                             DEVICES                                                */
  11. /* ******************************************************************************************** */
  12.  
  13. execute file "DeviceHelp";
  14.  
  15. /* ******************************************************************************************** */
  16. /*                                             BACKUP/RESTORE                                        */
  17. /* ******************************************************************************************** */
  18.  
  19. PROCEDURE backup_server()
  20. {
  21.     describe databases into db;
  22.     for each db {
  23.         if ((varchar db->name != "Model")
  24.         and    (varchar db->name != "Master")) {
  25.             print "Backing Up Database", db->name;
  26.             backup database varchar db->name replace previous;
  27.         }
  28.     }
  29.     
  30.     open_master();
  31.     set variable Offlinefunction = "Archive";
  32.     close_master();
  33.     print "Backing Up Database Master";
  34.     backup database Master replace previous;
  35. } END PROCEDURE backup_server;
  36.  
  37. PROCEDURE restore_server(mode)
  38. ARGUMENT integer mode = 0;
  39. {
  40.     switch (mode) {
  41.         case 1:
  42.             print "Restoring The Master Database";
  43.             trans shutdown;
  44.             server restore;
  45.             server restart;
  46.  
  47.         case 2:
  48.             describe databases into db;
  49.             for each db {
  50.                 if ((varchar db->name != "Model")
  51.                 and    (varchar db->name != "Master")) {
  52.                     print "Restoring The Database: ", db->name;
  53.                     restore database varchar db->name;
  54.                 }
  55.             }
  56.             break;
  57.  
  58.         default:
  59.             print "restore_server (mode)";
  60.             print "mode = 1: restore master database along with the user databases";
  61.             print "mode = 2: restore only the user databases, not the master database";
  62.     }
  63. } END PROCEDURE restore_server;
  64.  
  65. PROCEDURE sync_backups()
  66. {
  67.     print "Syncronizing database backup counts";
  68.     open_master();
  69.     select max(BackupCount) +1 as cnt from sysdatabases into bc;
  70.     fetch of bc;
  71.     update sysdatabases set BackupCount = bc->cnt;
  72.     close_master();
  73. } END PROCEDURE sync_backups;
  74.  
  75. PROCEDURE help_backup()
  76. {
  77.     print "";
  78.     print "BACKUP  & RESTORE:";
  79.     print "------------------";
  80.     print "The following functions are provided to perform high level server";
  81.     print "backups.";
  82.     print "";
  83.     print "PROCEDURE backup_server()";
  84.     print "Backup all databases on the server except the model database.";
  85.     print "";
  86.     print "PROCEDURE restore_server(mode)";
  87.     print "Restore all databases on the server from the last backup.";
  88.     print "This function will optionaly restore the master database:";
  89.     print "mode = 1: restore ALL database (Master database first).";
  90.     print "mode = 2: restore only the user databases.";
  91.     print "";
  92.     print "PROCEDURE sync_backups()";
  93.     print "Syncronize the backup count of all databases."; 
  94.     print "Each database contains an entry in the master database saying how";
  95.     print "many times it has been backed up. This number is used to determine";
  96.     print "the next backup group. All subsequent executions of 'backup_server()'";
  97.     print "will place all database backups in the same group.";
  98.     print "";
  99. } END PROCEDURE help_backup;
  100.  
  101. /* ******************************************************************************************** */
  102. /*                                             BACKUP GROUPS                                        */
  103. /* ******************************************************************************************** */
  104.  
  105. PROCEDURE help_groups()
  106. {
  107.     print "";
  108.     print "BACKUP GROUPS:";
  109.     print "--------------";
  110.     print "Several backup devices can be selected for placing backups as they";
  111.     print "are created. A collection of devices for a backup are called a group";
  112.     print "Backup groups are automatically numbered 1, 2, 3, ... n.";
  113.     print "Backups are done to each group in turn. For example, if the last";
  114.     print "backup of database 'x' was in group 2, then the next will be in 3.";
  115.     print "And if the last backup was in group 'n', then the next will be in";
  116.     print "group 1. Note that removing a backup group will causes all backup";
  117.     print "groups after that to be renumbered.";
  118.     print "";
  119.     print "PROCEDURE list_backup_groups()";
  120.     print "List all backup groups.";
  121.     print "";
  122.     print "PROCEDURE add_backup_group(group)";
  123.     print "Add an 'empty' backup group.";
  124.     print "";
  125.     print "PROCEDURE new_backup_group(group, device)";
  126.     print "Add a new backup group and place index and data on the given device.";
  127.     print "";
  128.     print "PROCEDURE alter_backup_group(group, device, data, index)";
  129.     print "Alter a given database group. Specify a device name and whether";
  130.     print "data or index files should be placed on the device ($true) or";
  131.     print "not ($false). If the status of data or index on the device";
  132.     print "should remain unaltered, specify $null.";
  133.     print "";
  134.     print "PROCEDURE remove_backup_group(group)";
  135.     print "Remove a particular backup group.";
  136.     print "";
  137. } END PROCEDURE help_groups;
  138.  
  139. PROCEDURE find_backup_location(group, device, type, print_error)
  140. RETURNS integer;
  141. ARGUMENT integer group;
  142. ARGUMENT varchar device, type;
  143. ARGUMENT boolean print_error = $TRUE;
  144. {
  145.     integer dev_id;
  146.     
  147.     dev_id = find_device(device);
  148.     if (dev_id == 0)
  149.         return(0);
  150.     
  151.     open_master;
  152.     select id
  153.     from  $sm_master!syslocations
  154.     where .FilePurpose = "FutureBackup"
  155.     and   .GroupNumber = :group
  156.     and   .DeviceID = :dev_id
  157.     and   .FileType = :type
  158.     order by id
  159.     into $cur for extract;
  160.     if ($rows($cur) == 0) {
  161.         if (print_error)
  162.             print $format("ERROR: Backup group '%d' does not locate %s files on device '%s'.",
  163.                 group, $tolower(type), device);
  164.         return(0);
  165.     }
  166.     fetch first of $cur;
  167.     return($cur->id);
  168. } END PROCEDURE find_backup_location;
  169.  
  170. PROCEDURE remove_backup_location(group, device, type)
  171. RETURNS integer;
  172. ARGUMENT integer group;
  173. ARGUMENT varchar filetype;
  174. {
  175.     integer loc_id;
  176.     
  177.     loc_id = find_backup_location(group, device, type);
  178.     if (loc_id != 0)
  179.         REMOVE LOCATION (loc_id);
  180.     return(loc_id);
  181. } END PROCEDURE remove_backup_location;
  182.  
  183. PROCEDURE add_backup_location(group, device, type)
  184. RETURNS integer;
  185. ARGUMENT integer group;
  186. ARGUMENT varchar device;
  187. ARGUMENT varchar type;
  188. {
  189.     integer dev_id;
  190.     integer loc_id;
  191.     
  192.     dev_id = find_device(device);
  193.     if (dev_id == 0)
  194.         return(0);
  195.  
  196.     loc_id = find_backup_location(group, device, type, $FALSE);
  197.     if (loc_id == 0) {
  198.         ADD LOCATION (NAME = "Backup" + type + "Files" + varchar group,
  199.                       FILETYPE = type,
  200.                       FILEPURPOSE = "FutureBackup",
  201.                       DEVICEID = dev_id,
  202.                       GROUPNUMBER = group);
  203.         loc_id = find_backup_location(group, device, type, $FALSE);
  204.     }
  205.     return(loc_id);
  206. } END PROCEDURE add_backup_location;
  207.  
  208. PROCEDURE backup_group_count()
  209. RETURNS integer;
  210. {
  211.     open_master;
  212.     select max(groupnumber) as maxx
  213.     from $sm_master!syslocations
  214.     where .FilePurpose = "FutureBackup"
  215.     into $cur for extract;
  216.     if ($rows($cur) == 0)
  217.         return 0;
  218.     fetch first of $cur;
  219.     return($cur->maxx);
  220. } END PROCEDURE backup_group_count;
  221.  
  222. PROCEDURE find_backup_group(group, print_error)
  223. RETURNS boolean;
  224. ARGUMENT boolean print_error = $TRUE;
  225. {
  226.     open_master;
  227.     select id from $sm_master!syslocations
  228.     where .FilePurpose = "FutureBackup"
  229.     and   .GroupNumber = :group
  230.     order by id
  231.     into $cur for extract;
  232.     if ($rows($cur) == 0) {
  233.         if (print_error)
  234.             print $format("ERROR: Backup group '%d' does not exist.", group);
  235.         return($FALSE);
  236.     }
  237.     return ($TRUE);
  238. } END PROCEDURE find_backup_group;
  239.  
  240. PROCEDURE add_backup_group(group)
  241. ARGUMENT integer group;
  242. {
  243.     select id, filetype, groupnumber from $sm_master!syslocations
  244.     where .FilePurpose = "FutureBackup"
  245.     and   .GroupNumber is not null
  246.     and   GroupNumber >= :group
  247.     order by id
  248.     into $cur for extract;
  249.     for each $cur {
  250.         ALTER LOCATION ($cur->id,
  251.                         NAME = "Backup" + $cur->filetype + "Files" + varchar ($cur->groupnumber + 1),
  252.                         GROUPNUMBER = ($cur->groupnumber + 1));
  253.     }
  254. } END PROCEDURE add_backup_group;
  255.  
  256. PROCEDURE remove_backup_group(group)
  257. ARGUMENT integer group;
  258. {
  259.     select id from $sm_master!syslocations
  260.     where .FilePurpose = "FutureBackup"
  261.     and   .GroupNumber is not null
  262.     and   GroupNumber == :group
  263.     order by id
  264.     into $cur for extract;
  265.     for each $cur
  266.         REMOVE LOCATION ($cur->id);
  267.     
  268.     select id, filetype, groupnumber from $sm_master!syslocations
  269.     where .FilePurpose = "FutureBackup"
  270.     and   .GroupNumber is not null
  271.     and   GroupNumber > :group
  272.     order by id
  273.     into $cur for extract;
  274.     for each $cur {
  275.         ALTER LOCATION ($cur->id,
  276.                         NAME = "Backup" + $cur->filetype + "Files" + varchar ($cur->groupnumber - 1),
  277.                         GROUPNUMBER = ($cur->groupnumber - 1));
  278.     }
  279. } END PROCEDURE remove_backup_group;
  280.  
  281. PROCEDURE alter_backup_group(group, device, data, index)
  282. ARGUMENT integer group;
  283. ARGUMENT generic device;
  284. ARGUMENT boolean data, index;
  285. {
  286.     if (data is not null) {
  287.         if (data)
  288.             add_backup_location(group, device, "Data");
  289.         else
  290.             remove_backup_location(group, device, "Data");            
  291.     }
  292.     if (index is not null) {
  293.         if (index)
  294.             add_backup_location(group, device, "Index");
  295.         else
  296.             remove_backup_location(group, device, "Index");            
  297.     }
  298.  
  299.     if (not find_backup_group(group, $FALSE))
  300.         remove_backup_group(group);
  301. } END PROCEDURE alter_backup_group;
  302.  
  303. PROCEDURE new_backup_group(group, device)
  304. ARGUMENT integer group;
  305. ARGUMENT generic device;
  306. {
  307.     add_backup_group(group);
  308.     alter_backup_group(group, device, $TRUE, $TRUE);
  309. } END PROCEDURE new_backup_group;
  310.  
  311. PROCEDURE list_backup_groups()
  312. {
  313.     integer group, dev_id;
  314.     boolean data, index;
  315.  
  316.     open_master;
  317.     select loc.groupnumber, loc.filetype, dev.id as dev_id, dev.name as devname, dev.path
  318.     from $sm_master!syslocations as loc,
  319.          $sm_master!sysdevices as dev
  320.     where loc.FilePurpose = "FutureBackup"
  321.     and   loc.deviceid = dev.id
  322.     and   loc.groupnumber is not null
  323.     order by GroupNumber, dev.id, loc.filetype
  324.     into $cur for extract;
  325.     
  326.     print 'Group:          Device:                 Data:        Index:';
  327.     print '--------------- ----------------------- ------------ -----------';
  328.     fetch first of $cur;
  329.     while ($sqlcode != $sqlnotfound) {
  330.         group = $cur->groupnumber;
  331.         dev_id = $cur->dev_id;
  332.         data = $FALSE;
  333.         index = $FALSE;
  334.  
  335.         printf("%-16d%-24s", group, $cur->devname);
  336.         
  337.         while ($sqlcode != $sqlnotfound) {
  338.             if (group = $cur->groupnumber and
  339.                 dev_id = $cur->dev_id) {
  340.                 if ($cur->filetype == "Data")
  341.                     data = $TRUE;
  342.                 if ($cur->filetype == "Index")
  343.                     index = $TRUE;
  344.             }
  345.             else
  346.                 break;
  347.             fetch next of $cur;
  348.         }
  349.  
  350.         if (data)
  351.             printf("YES          ");
  352.         else
  353.             printf(" -           ");
  354.         if (index)
  355.             print "YES          ";
  356.         else
  357.             print " -           ";
  358.     }
  359. } END PROCEDURE list_backup_groups;
  360.  
  361. /* ******************************************************************************************** */
  362. /*                                             HELP                                                */
  363. /* ******************************************************************************************** */
  364.  
  365. PROCEDURE help_all()
  366. {
  367.     help_backup;
  368.     help_groups;
  369. } END PROCEDURE help_all;
  370.  
  371. PROCEDURE help()
  372. {
  373.     print "";
  374.     print "BACKUP ADMINSTRATION:";
  375.     print "---------------------";
  376.     print "The folowing help functions are available:";
  377.     print "help_backup;";
  378.     print "help_groups;";
  379.     print "help_all;";
  380.     print "";
  381. } END PROCEDURE help;
  382.  
  383. print "Backup adminstration help functions defined.";
  384. print "Enter: 'help;' for help.";
  385.  
  386.